package edu.kit.ksri.db.mturk.var;

import edu.kit.ksri.db.mturk.plugins.performance.AbstractForecast;
import edu.kit.ksri.db.mturk.plugins.performance.SimpleLinearForecast;
import edu.kit.ksri.db.mturk.simulations.performance.PerfSimMTurk;
import edu.kit.ksri.db.mturk.simulations.performance.PerfSimWorker;
import edu.kit.ksri.db.mturk.utils.messaging.HITResultFetcher;
import edu.kit.ksri.db.mturk.utils.messaging.ResultQueue;

/**
 * Copyright (c) 2010-2011 Karlsruhe Institute of Technology (KIT), Germany
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 * 
 * --------------------------------------------------------------------------
 * 
 * Software: CSP/WMV tool for dynamic quality management of microtasks
 * http://www.ksri.kit.edu/Upload/Users/PeopleClouds/HCOMP2011_An_extendable_toolkit_for_managing_quality_of_human-based_eServices.pdf
 * 
 * Organization: Karlsruhe Institute of Technology (KIT), Germany
 * http://www.kit.edu
 * 
 * Project: PeopleClouds project of the Karlsruhe Service Research Institute(KSRI)
 * http://www.ksri.kit.edu/Default.aspx?PageId=818
 * 
 * Contributing authors: David Bermbach, Sandra Rath, Pascal Wichmann, Robert Kern
 * 
 * ---------------------------------------------------------------------------
 * 
 * Purpose: This class stores all kinds of static information and is accessed by other
 * classes afterwards
 */
public class StaticInformation {

	/** 
	 * The instance of the current scenario 
	 * Currently the following are available: 
	 * "Poker" or "Ocr" or "Icd" (the latter for testing only)
	 */
	//public static final Scenario scenario = Ocr.INSTANCE;
	public static final Scenario scenario = AddressResearch.INSTANCE;
	
	/**
	 * Turns the HTML monitoring plug-in on or off
	 */
	//public static final boolean isMonitoring = true;
	public static final boolean isMonitoring = false;
	
	/**
	 * If true, the monitoring also shows the HITs that haven't been touched yet
	 */
	//public static final boolean showNewHITsInMonitoring = false;
	public static final boolean showNewHITsInMonitoring = true;
	
	/**
	 * When more than x results are submitted, then only the summary is shown.
	 * Enter -1 when you always want to see the results and the summary.
	 * Enter 0 when you always want to see the summary only.
	 */
	public static final int showOnlySummaryWhenMoreThanResults = -1;
	
	/** The location of the properties file for the library */
	public static final String mturkFile = "mturk.properties";

	/**
	 * how often shall {@link AbstractCSP1Implementation} poll the
	 * {@link ResultQueue} for new messages. This specifies the delay between
	 * polling the queue.
	 */
	// live experiments:
	//public static final long millisBetweenQueuePolling = 2000;
	// simulation:
	public static final long millisBetweenQueuePolling = 20;

	/**
	 * how often shall the {@link HITResultFetcher} poll MTurk for new results?
	 * Makes sense to be smaller than millisBetweenQueuePolling
	 */
	// live experiments:
	//public static final long millisBetweenMTurkPolling = 1500;
	// simulation:
	public static final long millisBetweenMTurkPolling = 5;

	/**
	 * the qualification value assigned to a worker who may work on a given task
	 */
	public static final int activePoolQualificationValue = 1;

	/**
	 * the qualification value assigned to members of the pending pool, must be
	 * less than activePoolQualificationValue
	 */
	public static final int pendingPoolQualificationValue = 0;

	/**
	 * the qualification value assigned to members of the blocked pool, must be
	 * less than activePoolQualificationValue
	 */
	public static final int blockedPoolQualificationValue = -1;
	
	/**
	 * the number of seconds which shall elapse between snapshots of the
	 * performance plugin
	 */
	public static final int secondsBetweenSnapshots = 5;

	/**
	 * which subclass of {@link AbstractForecast} shall be used to forecast the
	 * productivity of the next period based on historic productivities
	 */
	public static final Class<? extends AbstractForecast> forecastClass = SimpleLinearForecast.class;

	/**
	 * determines how often {@link PerfSimWorker}s will do something. unit is
	 * milliseconds
	 */
	//public static final int updateIntervalForSimWorkers = 1000;
	public static final int updateIntervalForSimWorkers = 100;

	/**
	 * what is the minimum duration for a HIT completed by a {@link PerfSimWorker}
	 * in milliseconds. values between min and max are of uniform distribution.
	 */
	//public static final int minTaskDurationForSimWorkers = 2000;
	public static final int minTaskDurationForSimWorkers = 200;

	/**
	 * what is the maximum duration for a HIT completed by a {@link PerfSimWorker}
	 * in milliseconds. values between min and max are of uniform distribution.
	 */
	//public static final int maxTaskDurationForSimWorkers = 5000;
	public static final int maxTaskDurationForSimWorkers = 500;

	/**
	 * must be a value between 0 and 1. describes how likely it is that a
	 * {@link PerfSimWorker} accepts a given task or just does nothing instead
	 */
	public static final double hitAcceptanceProbabilityForSimWorkers = 0.8;
	
	
	/** time the simulated MTurk Platform waits before checking whether to announce a further HIT or not */
	//public static final long millisBetweenPublishingHITOnSimMTurk = 2000;
	public static final long millisBetweenPublishingHITOnSimMTurk = 200;
	
	/** maximum number of parallel HITs that can be worked at during a Simulation */
	public static int maxParallelSimHITs = 1000;
	
	/** maximum number of Assignments, a SimWorker can accomplish before first validation has to be submitted. In case of 0, there is no limit. */
	public static int frontRunningParamSimWorker = 1000;
	
	
	/** minimum required correctness level in order to be allowed for work */
	public static final double minimumCorrectnessLevel = 60.0;
	
	/**
	 * path and directory name where the data for the current scenario is located
	 */
	public static final String scenarioDirectory = "scenariodata" + "/" + scenario.getPrefix().toLowerCase();
	
	
	/**
	 * path and directory name where the results shall be persisted when the
	 * program terminates
	 */
	public static final String resultOutputDirectory = scenarioDirectory + "/" + "liveoutput";
	
	/**
	 * path and directory name where the live input data is located
	 */
	public static final String resultInputDirectory = scenarioDirectory + "/" + "liveinput";
	
	/**
	 * The path to the scenario-dependent simulation output directory. It contains the XML files after the simulation is done
	 */
	public static final String simMTurkOutputDirectory = scenarioDirectory + "/" + "simoutput";

	/**
	 * The path to the scenario-dependent simulation input directory. It contains the XML files for the simulation input
	 */
	public static final String simMTurkInputDirectory = scenarioDirectory + "/" + "siminput";
	
	/**
	 * file name where the information on all workers can be imported from
	 * before the HITs are published. # marks a comment line.
	 */
	public static final String workerFileIn = resultInputDirectory + "/" + "workers.txt";
	
	/**
	 * file name where the information on all workers shall be persisted
	 * after a run. # marks a comment line.
	 */
	public static final String workerFileOut = resultOutputDirectory + "/" + "workers.txt";
	
	/**
	 * file name where the information of all workers can be exported to
	 * after the simulation is done. # marks a comment line.
	 */
	public static final String workerSimOutputFile = simMTurkOutputDirectory + "/" + "workers.txt";
	
	/**
	 * file name where the information on all workers can be imported from
	 * before the simulation is done. # marks a comment line.
	 */
	public static final String workerSimInputFile = simMTurkInputDirectory + "/" + "workers.txt";

	/**
	 * In mode performance simulation this file should contain input parameters for the
	 * {@link PerfSimMTurk}.initialize() method, i.e. data in the form of<br>
	 * WORKER_ID,QUALIFICATION_VALUE,LIST_OF_ANSWERS <br>
	 * <br>
	 * where LIST_OF_ANSWERS is a comma-separated list of answer values which
	 * the specific worker should answer for the respective HIT. # marks a
	 * comment line.
	 */
	public static final String simMTurkInputFile = simMTurkInputDirectory + "/" + "siminput.txt";

	/**
	 * The input file is a tab delimited file where the first row defines the
	 * fields/variables and the remaining rows contain the values for each HIT.
	 * Each row represents a unique HIT. The SDK uses the Apache Velocity engine
	 * to merge the input values into a templatized QAP file. Please refer to
	 * http://velocity.apache.org for more details on this engine and how to
	 * specify variable names. Apache Velocity is fully supported so there may
	 * be additional functionality you can take advantage of if you know the
	 * Velocity syntax. <br>
	 * <br>
	 */
	public static final String inputFile = resultInputDirectory + "/" + scenario.getPrefix().toLowerCase() + ".input";

	/**
	 * The input file is a tab delimited file where the first row defines the
	 * fields/variables and the remaining rows contain the values for each HIT.
	 * Each row represents a unique HIT. The SDK uses the Apache Velocity engine
	 * to merge the input values into a templatized QAP file. Please refer to
	 * http://velocity.apache.org for more details on this engine and how to
	 * specify variable names. Apache Velocity is fully supported so there may
	 * be additional functionality you can take advantage of if you know the
	 * Velocity syntax. <br>
	 * <br>
	 * Is ignored in simulation mode except for display plugin.
	 */
	public static final String siminputFile = simMTurkInputDirectory + "/" + scenario.getPrefix().toLowerCase() + ".input";
	
	/**
	 * The question (QAP) file contains Apache Velocity variable names where the
	 * values from the input file are to be inserted. Essentially the QAP
	 * becomes a template for the input file.<br>
	 * <br>
	 * Is ignored in simulation mode.
	 */
	public static final String questionFile = resultInputDirectory + "/" + scenario.getPrefix().toLowerCase() + ".question";

	/**
	 * The HIT properties file defines two system qualifications that will be
	 * used for the HIT. The properties file can also be a Velocity template.
	 * Currently, only the "annotation" field is allowed to be a Velocity
	 * template variable. This allows the developer to "tie in" the input value
	 * to the results.<br>
	 * <br>
	 * Is ignored in simulation mode.
	 */
	public static final String propertiesFile = resultInputDirectory + "/" + scenario.getPrefix().toLowerCase() + ".properties";

	/**
	 * directory of the qualification test
	 */
	public static final String qualificationTestDirectory = scenarioDirectory + "/qualificationtest";
	
	/**
	 * path and file name to the qualification test answers file
	 */
	public static final String qualificationTestAnswersFile = qualificationTestDirectory + "/" + scenario.getPrefix().toLowerCase() + "test.answers";
	
	/**
	 * path and file name to the qualification test questions file
	 */
	public static final String qualificationTestQuestionsFile = qualificationTestDirectory + "/" + scenario.getPrefix().toLowerCase() + "test.question";
	
	/**
	 * path and file name to the qualification gold standard file
	 */
	public static final String qualificationGoldStandardFile = qualificationTestDirectory + "/goldstandard.txt";
	
	/**
	 * file name of the snapshots csv
	 */
	public static final String resultOutputSnapshots = resultOutputDirectory + "/snapshots.csv";
	
	/**
	 * path and directory where the duplicates are stored
	 */
	public static final String resultOutputDirectoryDuplicate = resultOutputDirectory + "/duplicate";
}
